package br.com.sisgerenciamento.util;

import java.io.IOException;
import java.text.MessageFormat;
import java.util.Properties;

public class MensagensResources {
	private static Properties propertie;

	private MensagensResources(){}

	public static String getString( String key ) {
		try {
			if ( propertie == null ) {
				propertie = new Properties();
				propertie.load( MensagensResources.class.getResourceAsStream( "/application.properties" ) );
			}

			return propertie.getProperty( key );
		} catch ( IOException e ) {
			e.printStackTrace();
			return '!' + key + '!';
		}
	}

	public static String getString( String key, String... parametros ) {
		return MessageFormat.format( getString( key ), parametros );
	}

	public static void setString( String key, String value ) {
		try {
			if ( propertie == null ) {
				propertie = new Properties();
				propertie.load( MensagensResources.class.getResourceAsStream( "/application.properties" ) );
			}
			propertie.setProperty( key, value );
		} catch ( IOException e ) {
			e.printStackTrace();
		}
	}
}
